%x IN_SYLLABLE AMBISYLLABIC
%{
int markers=1;
char *seperator="";
%}
plosive p|b|t|d|k|g
affricate pf|ts|tS|dZ
fricative f|v|s|z|S|Z|C|j|x|h
nasal N|m|n
liquid l|R|r
consonant {plosive}|{affricate}|{fricative}|{nasal}|{liquid}
shortvowel I|E|a|O|U|Y|9
longvowel i:|e:|E:|a:|o:|u:|y:|2:
diphtong aI|aU|OY|E6|I6|O6|U6|Y6|a6|2:6|E:6|a:6|e:6|i:6|o:6|u:6|y:6
schwa @|6
vowel {shortvowel}|{longvowel}|{diphtong}|{schwa}
phoneme {vowel}|{consonant}
marker \[|\]|\"

%%
<IN_SYLLABLE,AMBISYLLABIC>{plosive}          printf("%s%s",yytext,seperator);
 /*<IN_SYLLABLE,AMBISYLLABIC>{affricate}        printf("%s%s",yytext,seperator);*/
<IN_SYLLABLE,AMBISYLLABIC>{fricative}        printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>{nasal}            printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>{liquid}           printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>{shortvowel}       printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>{longvowel}        printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>{diphtong}         printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>{schwa}            printf("%s%s",yytext,seperator);
<IN_SYLLABLE,AMBISYLLABIC>(A|O|\{|9)~:?      printf("%s%s",yytext,seperator);
 /*<IN_SYLLABLE,AMBISYLLABIC>={consonant}       printf("%s%s",yytext,seperator);*/
<INITIAL>\[        { if (markers==1) 
		       {
			 printf("[%s",seperator);
		       }
		     BEGIN(IN_SYLLABLE);
		   }
<IN_SYLLABLE>\[    { if (markers==1) 
		       {
			 printf("[%s",seperator);
		       }
		     BEGIN(AMBISYLLABIC);
		   }
<IN_SYLLABLE>\]    { if (markers==1) 
		       {
			 printf("]%s",seperator);
		       }
		     BEGIN(INITIAL);
		   }
<AMBISYLLABIC>\]   { if (markers==1) 
		       {
			 printf("]%s",seperator);
		       }
		     BEGIN(IN_SYLLABLE);
		   }
<IN_SYLLABLE,AMBISYLLABIC>\"                { if (markers==1)
						{
						  printf("\"%s",seperator);
						}
					    }
<IN_SYLLABLE,AMBISYLLABIC>\#                { if (markers==1) 
						{
						  printf("#%s",seperator);
						}
					    }
. ;
%%
main(argc, argv)
int argc;
char **argv;
{
  int i;

  ++argv; --argc; /* skip over program name */
  if((argc>0)&&(strcmp(argv[0],"-s")==0)) {seperator=" "; ++argv; --argc;}
  if((argc>0)&&(strcmp(argv[0],"-n")==0)) {seperator="\n"; ++argv; --argc;}
  if((argc>0)&&(strcmp(argv[0],"-p")==0)) {markers=0; ++argv; --argc;}

  if(argc>0){
    for(i=0; i<argc; i++){

      yyin = fopen(argv[i],"r");
      if (yyin==NULL) 
        fprintf(stderr,"could not open %s --- skipped.\n",argv[i]);
      else {
        yylex();
      }
    }
  } else {
    yyin=stdin;
    yylex();
  }
}
